import React from 'react';
import {render} from 'react-dom';
import {Provider} from 'react-redux';
import {BrowserRouter} from 'react-router-dom';
import {renderRoutes} from 'react-router-config';

import utils from './utils';
import routes from './routes';
import {appDomain} from './config';
import createStore from './redux/createStore';

import 'normalize.css';

let initState;
let reduxDevCompose;

if (utils.isBrowser()) {
    initState = window.__INITIAL_STATE__ || {};
    reduxDevCompose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
}

const store = createStore(initState, undefined, reduxDevCompose);

const renderApp = () => {
    render(
        <Provider store={store}>
            <BrowserRouter basename={appDomain}>
                {renderRoutes(routes)}
            </BrowserRouter>
        </Provider>,
        document.querySelector('.container')
    );
};

renderApp();

if (module.hot) {
    module.hot.accept();
}
